<?php


namespace app\models;


use think\Model;

class Base extends Model {
    public static function getInfoById($id, $field = '*') {
        $info = self::where('id', '=', $id)->field($field)->find();
        if($info) {
            $info = $info->toArray();
        }
        return $info;
    }

    public static function getInfo($where = [], $field = '*') {
        $info = self::where($where)->field($field)->find();
        if($info) {
            $info = $info->toArray();
        }
        return $info;
    }

    public static function getPageList($where = [], $page = 1, $limit = 20, $field = '*', $orderby = 'id desc') {
        $list = self::where($where)->field($field)->order($orderby)->page($page, $limit)->select()->toArray();
        $count = self::where($where)->count();
        return [
            'list' => $list,
            'count' => $count
        ];
    }

    public static function getList($where = [], $field = '*', $orderby = 'id desc', $limit = 0) {
        $db = self::where($where)->field($field)->order($orderby);
        if($limit) {
            $db = $db->limit($limit);
        }
        return $db->select()->toArray();
    }

    public static function getListByIds($ids, $field = '*', $orderby = 'id desc') {
        return self::whereIn('id', $ids)->field($field)->order($orderby)->select()->toArray();
    }

    public static function getCount($where) {
        return self::where($where)->count();
    }
}